package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.pojo.exceptional.CdzExceptionalRetroaction;
import com.zhentao.service.CdzExceptionalRetroactionService;
import com.zhentao.mapper.CdzExceptionalRetroactionMapper;
import com.zhentao.userLocal.UserThreadLocalUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author 岳大大
* @description 针对表【cdz_exceptional_retroaction】的数据库操作Service实现
* @createDate 2024-12-25 11:21:14
*/
@Service
public class CdzExceptionalRetroactionServiceImpl extends ServiceImpl<CdzExceptionalRetroactionMapper, CdzExceptionalRetroaction>
    implements CdzExceptionalRetroactionService{

    @Override
    public ResponseResult add(CdzExceptionalRetroaction cdzExceptionalRetroaction) {
        cdzExceptionalRetroaction.setCreateTime(new Date());
        boolean save = this.save(cdzExceptionalRetroaction);
        return save ? ResponseResult.okResult("添加成功") : ResponseResult.errorResult(20001,"添加失败");
    }

    @Override
    public ResponseResult select() {
        //获取登录id
        Long userId = UserThreadLocalUtil.getUser();
        //根据用户id查询异常列表
        LambdaQueryWrapper<CdzExceptionalRetroaction> queryWrapper = Wrappers.<CdzExceptionalRetroaction>lambdaQuery()
                .eq(CdzExceptionalRetroaction::getUserId, userId)
                .eq(CdzExceptionalRetroaction::getIsDel, 1);
        if (list(queryWrapper) != null) {
            return ResponseResult.okResult(list(queryWrapper));
        }else {
            return ResponseResult.errorResult(20001,"暂无数据");
        }
    }
}




